package br.com.webcrm.view;

import java.util.List;

import br.com.webcrm.model.Endereco;

@SuppressWarnings("serial")
public class EnderecoDataModel extends PrimeDataModel<Endereco> {

    public EnderecoDataModel() {
    }

    public EnderecoDataModel(Object data) {
        super(data);
    }
    
    @SuppressWarnings("unchecked")
	@Override
    public Endereco getRowData(String rowKey) {
        //In a real app, a more efficient way like a query by rowKey should be implemented to deal with huge data
        
        List<Endereco> enderecos = (List<Endereco>) getWrappedData();
        
        for(Endereco endereco : enderecos) {
        	String id = ""+endereco.getIdEndereco();
            if(id.equals(rowKey))
                return endereco;
        }
        
        return null;
    }

    @Override
    public String getRowKey(Endereco endereco) {
        return ""+endereco.getIdEndereco();
    }
}
                    
